package org.example.sword2offer.medium;

import java.util.Arrays;

/**
 * @author: lynn
 * @Descript: 最少的箭，射最多的气球
 * @date: 2022/2/12 22:17
 * @version: 1.0
 */
public class MostArrow {

    public static void main(String[] args) {
        Area[] areas=new Area[]{new Area(1,3),new Area(2,5),new Area(2,6),new Area(4,7),new Area(6,7),new Area(9,11)};
        System.out.println(lessArrow(areas));
    }

    private  static class Area{
        int start;
        int end;
        Area(int start,int end){
            this.start=start;
            this.end=end;
        }
    }

    private  static int lessArrow(Area[] areas){
        Arrays.sort(areas,(o1,o2)->{
            return o1.end-o2.end;
        });
        int count=0;

        for (int j = 0; j <areas.length ; j++) {
            int temp=0;
            for (int i = 0; i <areas.length ; i++) {
                if (areas[i].end>=areas[j].end && areas[i].start<=areas[j].end){
                    temp++;
                }
            }
            count=temp>=count?temp:count;
        }
        return count;
    }
}
